package com.ruoyi.web.controller.part;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PartType;
import com.ruoyi.system.service.IPartTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 停车场类型Controller
 * 
 * @author ruoyi
 * @date 2024-01-04
 */
@RestController
@RequestMapping("/part/type")
public class PartTypeController extends BaseController
{
    @Autowired
    private IPartTypeService partTypeService;

    /**
     * 查询停车场类型列表
     */
    @PreAuthorize("@ss.hasPermi('part:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(PartType partType)
    {
        startPage();
        List<PartType> list = partTypeService.selectPartTypeList(partType);
        return getDataTable(list);
    }

    /**
     * 导出停车场类型列表
     */
    @PreAuthorize("@ss.hasPermi('part:type:export')")
    @Log(title = "停车场类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PartType partType)
    {
        List<PartType> list = partTypeService.selectPartTypeList(partType);
        ExcelUtil<PartType> util = new ExcelUtil<PartType>(PartType.class);
        util.exportExcel(response, list, "停车场类型数据");
    }

    /**
     * 获取停车场类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('part:type:query')")
    @GetMapping(value = "/{partTypeId}")
    public AjaxResult getInfo(@PathVariable("partTypeId") Long partTypeId)
    {
        return success(partTypeService.selectPartTypeByPartTypeId(partTypeId));
    }

    /**
     * 新增停车场类型
     */
    @PreAuthorize("@ss.hasPermi('part:type:add')")
    @Log(title = "停车场类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PartType partType)
    {
        return toAjax(partTypeService.insertPartType(partType));
    }

    /**
     * 修改停车场类型
     */
    @PreAuthorize("@ss.hasPermi('part:type:edit')")
    @Log(title = "停车场类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PartType partType)
    {
        return toAjax(partTypeService.updatePartType(partType));
    }

    /**
     * 删除停车场类型
     */
    @PreAuthorize("@ss.hasPermi('part:type:remove')")
    @Log(title = "停车场类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{partTypeIds}")
    public AjaxResult remove(@PathVariable Long[] partTypeIds)
    {
        return toAjax(partTypeService.deletePartTypeByPartTypeIds(partTypeIds));
    }
}
